import PostalMime from 'postal-mime';

export const email = async (message: ForwardableEmailMessage, env: Env, ctx: ExecutionContext) => {
  const rawEmail = await new Response(message.raw).text();
  const parsedEmail = await PostalMime.parse(rawEmail);
  const html = parsedEmail.html || parsedEmail.text || '';
  const now = Date.now().toString();
  await env.KVDATA.put(now, html);
}
